home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8271 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: rcp6.elan.af.mil!rscernix!danpop
  2. From: danpop@mail.cern.ch (Dan Pop)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: realloc(NULL,100)
  5. Date: 28 Feb 96 16:34:11 GMT
  6. Organization: CERN European Lab for Particle Physics
  7. Message-ID: <danpop.825525251@rscernix>
  8. References: <31346CB0.41C67EA6@jupiter.di.uminho.pt>
  9. NNTP-Posting-Host: ues5.cern.ch
  10. X-Newsreader: NN version 6.5.0 #7 (NOV)
  11.  
  12. In <31346CB0.41C67EA6@jupiter.di.uminho.pt> Rui Bastos <rui@jupiter.di.uminho.pt> writes:
  13.  
  14. >   Does anybody knows what's the expected behaviour of this program?
  15.  
  16. Undefined, because you include the nonstandard header <malloc.h> and
  17. use realloc without including <stdlib.h> (or declaring it yoursef).
  18.  
  19. >#include <stdio.h>
  20. >#include <malloc.h>
  21.  
  22. s/malloc/stdlib
  23.  
  24. >main()
  25. >{
  26. >   void *x=NULL;
  27. >   x=realloc(NULL,100);
  28. >   printf("%p\n",x);
  29. >}
  30. >
  31. >  I tested it under diferent compilers/operating systems
  32. >and  it returns null, others returns a valid address and other
  33. >crashes.
  34.  
  35. On systems with pre-ANSI libraries, a crash was the usual behaviour.
  36. On systems with ANSI libraries, both zero and nonzero results are legal.
  37. Zero means that realloc couldn't allocate a 100-byte memory block for you.
  38.  
  39. >PS please and send me an email if you reply to this post.
  40.  
  41. Because you're too f***ing lazy to look for answers in the newsgroup?
  42. Or is it because your time is precious, while ours is worth peanuts?
  43.  
  44. Dan
  45. --
  46. Dan Pop
  47. CERN, CN Division
  48. Email: danpop@mail.cern.ch 
  49. Mail:  CERN - PPE, Bat. 31 R-004, CH-1211 Geneve 23, Switzerland
  50.